home *** CD-ROM | disk | FTP | other *** search
- /*
- TrackToAbs XFCN v1.0
-
- ©1991 Apple Computer, Inc.; by Mike Byrne
-
- Takes a track number and a time in that track and converts it to the absolute time on
- the disc. Note that the CD-Audio XCMDs *must* be present, and a CD must be in the drive...
-
- Form:
- TrackToAbs(<track#>, <time>)
-
- # the MPW 3.2 build commands:
- C -b TrackToAbs.c -mbg off
- Link -w -t STAK -c WILD -rt XFCN=703 ∂
- -m ENTRYPOINT ∂
- -sg TrackToAbs ∂
- TrackToAbs.c.o ∂
- "{Libraries}HyperXLib.o" ∂
- "{Libraries}Runtime.o" ∂
- "{Libraries}Interface.o" ∂
- "{CLibraries}StdCLib.o" ∂
- -o "teststack"
- */
-
- #include <Types.h>
- #include <string.h>
- #include <Memory.h>
- #include "HyperXcmd.h"
-
- #define NULL (long) 0
- #define NIL (long) 0
-
- #define kNumParams 2
- #define blocksInSec 75
- #define secsInMin 60
-
-
- /* prototypes */
- void ErrorBack(XCmdPtr paramPtr, char *message);
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
- void UnlockParams ( XCmdPtr paramPtr, short paramCount );
- void StringToInts( char* theString, long* mint, long* sint, long* bint);
- void IntsToString(char* retString, long mint, long sint, long bint);
-
- pascal void EntryPoint(XCmdPtr paramPtr)
- {
-
- /* variable declarations */
- long mint1, sint1, bint1;
- long mint2, sint2, bint2;
- long mintr, sintr, bintr;
- long carry = 0;
- char retString[10];
- char msgString[40];
- Handle dummyHandle;
-
- /* move high and lock the parameters. */
- MoveLockParams(paramPtr, paramPtr->paramCount);
-
- /* check for copyright or syntax help request */
- if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
- ErrorBack(paramPtr, "v1.0, ©1991 Apple Computer, Inc.; by Mike Byrne");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
- ErrorBack(paramPtr, "TrackToAbs syntax is 'TrackToAbs(<track#>, <time>)'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* not a copyright or help request. */
- /* check for correct number of parameters */
- if (paramPtr->paramCount != kNumParams) {
- ErrorBack(paramPtr, "Error: TrackToAbs syntax is 'TrackToAbs(<track#>, <time>)'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* verify that there is a CD in there */
- dummyHandle = GetGlobal(paramPtr, "\pxxxCDRefNum");
- if ( !strcmp( (char*)*dummyHandle, "0") ) {
- ErrorBack(paramPtr, "Error: There is no audio CD available");
- UnlockParams(paramPtr, paramPtr->paramCount);
- DisposHandle(dummyHandle);
- return;
- }
- DisposHandle(dummyHandle);
-
- /* get the start time */
- strcpy( msgString, "line ");
- strcat( msgString, (char*) *paramPtr->params[0]);
- strcat( msgString, " of CDTOCLines()" );
- c2pstr(msgString);
- dummyHandle = EvalExpr(paramPtr, msgString);
-
- /* check to see if we got anything in the string */
- if (strlen( (char*) *dummyHandle ) < 1) {
- ErrorBack(paramPtr, "Error: That is not a valid track for this disc.");
- UnlockParams(paramPtr, paramPtr->paramCount);
- DisposHandle(dummyHandle);
- return;
- }
-
- /* check to see if the first char in the string is a "-" (an error) */
- if ( (*dummyHandle)[0] == '-' ) {
- ErrorBack(paramPtr, "Error: Could not get disc information.");
- UnlockParams(paramPtr, paramPtr->paramCount);
- DisposHandle(dummyHandle);
- return;
- }
-
-
- /* convert the times to integers */
- StringToInts( (char*)*dummyHandle, &mint1, &sint1, &bint1);
- StringToInts( (char*)*paramPtr->params[1], &mint2, &sint2, &bint2);
-
- /* add them, with carrying */
- carry = (bint1 + bint2) / blocksInSec;
- bintr = (bint1 + bint2) % blocksInSec;
- sintr = sint1 + sint2 + carry;
- carry = sintr / secsInMin;
- sintr = sintr % secsInMin;
- mintr = mint1 + mint2 + carry;
-
- /* convert the numbers back to a string and go home */
- IntsToString(retString, mintr, sintr, bintr);
- DisposHandle(dummyHandle);
- ErrorBack(paramPtr, retString);
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
-
- }
-
-
-
- /* convert a string of the form "mm,ss,bb" to three shorts
- ------------------------------------------------------- */
- void StringToInts( char* theString, long* mint, long* sint, long* bint)
- {
- char* mptr;
- char* sptr;
- char* bptr;
- char mstr[5], sstr[5], bstr[5];
-
- mptr = strtok(theString, ",");
- sptr = strtok(NULL, ",");
- bptr = strtok(NULL, ",");
- strcpy(mstr, mptr);
- strcpy(sstr, sptr);
- strcpy(bstr, bptr);
- c2pstr(mstr);
- c2pstr(sstr);
- c2pstr(bstr);
- StringToNum(mstr, mint);
- StringToNum(sstr, sint);
- StringToNum(bstr, bint);
- }
-
-
-
- /* convert three integers to a c string of the form "mm,ss,bb"
- ----------------------------------------------------------- */
- void IntsToString(char* retString, long mint, long sint, long bint)
- {
- Str255 mstr, sstr, bstr;
-
- NumToString(mint, mstr);
- NumToString(sint, sstr);
- NumToString(bint, bstr);
- p2cstr(mstr);
- p2cstr(sstr);
- p2cstr(bstr);
- strcpy(retString, mstr);
- strcat(retString, ",");
- strcat(retString, sstr);
- strcat(retString, ",");
- strcat(retString, bstr);
- }
-
-
- /* allocate and load up paramPtr->returnValue with a string
- -------------------------------------------------------- */
- void ErrorBack(XCmdPtr paramPtr, char *message)
- {
- Handle mesHnd;
-
- /*
- Allocate space for an error message.
- Copy the string into it.
- Return the handle to HyperCard.
- */
- mesHnd = NewHandle((long)(strlen(message)+1));
- if (mesHnd == nil) return;
- strcpy((char *)*mesHnd,message);
- paramPtr->returnValue = mesHnd;
- }
-
-
-
- /* move high and lock down all parameters
- ----------------------------------------------------------------------- */
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
- {
- short i;
-
- for(i=0; i <= paramCount-1; i++)
- {
- MoveHHi(paramPtr->params[i]);
- HLock(paramPtr->params[i]);
- }
- }
-
-
-
-
- /* unlock all parameter handles in the XFCNBlock
- --------------------------------------------- */
- void UnlockParams ( XCmdPtr paramPtr, short paramCount )
- { short i;
-
- for(i=0; i <= paramCount-1; i++)
- { HUnlock(paramPtr->params[i]);}
- }
-